/**
 * Created by yangxianming on 2019/2/1.
 * 测试结果页面js
 */
function initData(){
    var today = new Date().format("yyyy-MM-dd");
    document.getElementById("exetime").placeholder = today;
    //加载第一页数据
    getInterFaceRep(drawInterFaceRep, 1);
    //设置分页方法
    splitPage(getInterFaceRep);
    //加载单选方法
    document.getElementById("greater").onclick = function () {switchGreaterSess(this)};
    document.getElementById("less").onclick = function () {switchGreaterSess(this)};
}

function queryReport(){
    getInterFaceRep(drawInterFaceRep, 1);
    //var date = document.getElementById("date").value;
    //getReport(date, 1);
}

function queryReportKeyboard(event){
    var e = event || window.event;
    if (e && e.keyCode ==13){
        var date = document.getElementById("date").value;
        getReport(date, 1);
    }
}

//大于小于切换
function switchGreaterSess(ob){
    var l = document.getElementById("less");
    var g = document.getElementById("greater");
    var whichId = ob.getAttribute("id");
    if (whichId == "greater"){
        l.checked = false;
        l.removeAttribute("disabled");
        g.setAttribute("disabled", "disabled")
    }
    if (whichId == "less"){
        g.checked = false;
        g.removeAttribute("disabled");
        l.setAttribute("disabled", "disabled");
    }
}

//分页方法
function splitPage(pageList){
    //设置分页方法 empListGO
    var listGO = document.getElementById("listGO");
    listGO.onclick = function () {
        var listC = document.getElementById("listC").value;
        pageList(drawInterFaceRep, listC);
    };

    //设置分页方法 empListP
    var listP = document.getElementById("listP");
    listP.onclick = function (){
        var listC = parseInt(document.getElementById("listC").value);
        if(listC == 1){
            return;
        }
        listC = listC - 1;
        document.getElementById("listC").value = listC;
        pageList(drawInterFaceRep, listC);
    };

    //设置分页方法 empListN

    var listN = document.getElementById("listN");
    listN.onclick = function (){
        var listPageCount = parseInt(document.getElementById("listPageCount").innerText);
        var listC = parseInt(document.getElementById("listC").value);
        if(listC == listPageCount){
            return;
        }
        listC = listC + 1;
        document.getElementById("listC").value = listC;
        pageList(drawInterFaceRep, listC);
    }
}

function getInterFaceRep(dofun, toPage){
    var module = selectedText(document.getElementById("module"));
    if (module == "全部"){
        module = "";
    }
    var path = document.getElementById("path").value;
    var caseid = document.getElementById("caseid").value;
    var userCase = document.getElementById("userCase").value;
    var exetime = document.getElementById("exetime").value;
    var restime = selectedValue(document.getElementById("restime"));
    var gl = document.getElementById("greater").checked ? "greater" : "less";
    var par = "action=apiReportTest";
    par = par + "&module=" + module;
    par = par + "&path=" + path;
    par = par + "&caseid=" + caseid;
    par = par + "&userCase=" + userCase;
    par = par + "&exetime=" + exetime;
    par = par + "&gl=" + gl;
    par = par + "&restime=" + restime;
    par = par + "&toPage=" + toPage;

    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("get", "/apiTestResult/queryApiTestResult?" + par, true);
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
                var r = JSON.parse(xmlHttp.response);
                if (r["apiStatus"] == "1"){
                    //页面总数
                    document.getElementById("listPageCount").innerText = r["result"]["pageCount"];
                    dofun(r["result"]["resultArr"]);
                }else{
                    alert(r["errorMsg"]);
                }
            }else{
                alert("服务器异常");
            }
        }
    };
    xmlHttp.send();
}

//
//页面渲染 都是以draw开头
//function drawGetCorpList(data){}
//
function drawInterFaceRep(data){
    var th = document.getElementById("th");
    var progressList = document.getElementById("interFaceList");
    progressList.innerText = "";
    progressList.appendChild(th);

    for (var i=0; i<data.length; i++){

        var tr = document.createElement("tr");
        var td1 = document.createElement("td");
        td1.innerText = data[i][0];
        tr.appendChild(td1);

        var td2 = document.createElement("td");
        td2.innerText = data[i][1];
        tr.appendChild(td2);

        var td3 = document.createElement("td");
        td3.innerText = data[i][2];
        tr.appendChild(td3);

        var td4 = document.createElement("td");
        td4.innerText = data[i][3];
        tr.appendChild(td4);

        var td5 = document.createElement("td");
        td5.innerText = data[i][4];
        tr.appendChild(td5);

        var td6 = document.createElement("td");
        td6.innerText = data[i][5];
        tr.appendChild(td6);

        var td7 = document.createElement("td");
        td7.innerText = data[i][6];
        tr.appendChild(td7);

        var td8 = document.createElement("td");
        td8.innerText = data[i][7];
        tr.appendChild(td8);



        progressList.appendChild(tr);
    }

}